using UnityEngine;
using System.Collections;
using System.Configuration;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.IO;
using System.Xml;
using System;


public class SABattleMapConfig : Singleton< SABattleMapConfig > 
{
	int[] map = null;

	
	void Awake ()
	{
		if ( mInstance == null )
		{
			mInstance = this;
			
			// init here ,
			
			initConfig();
		}
	}


	
	public void load( string path )
	{
		path = GameSetting.StreamingAssetsPath + path + ".xml";
		
		XmlDocument xmlDoc = new XmlDocument();  
		xmlDoc.Load( path ); 
		
		XmlNodeList node = xmlDoc.SelectSingleNode( "root" ).ChildNodes;

		map = new int[ 65535 ];

		foreach( XmlElement nodeList in node )
		{
			if ( nodeList.Name == "b" )
			{
				int[] id = new int[ 3 ];
				id[ 0 ] = Convert.ToInt32( nodeList.GetAttribute( "i0" ) );
				id[ 1 ] = Convert.ToInt32( nodeList.GetAttribute( "i1" ) );
				id[ 2 ] = Convert.ToInt32( nodeList.GetAttribute( "i2" ) );

				foreach( XmlElement xe in nodeList ) 
				{
					int min = Convert.ToInt32( xe.GetAttribute( "min" ) );
					int max = Convert.ToInt32( xe.GetAttribute( "max" ) );

					if ( max > 65535 )
					{
						max = 65535 - 1;
					}

					for ( int i = min ; i <= max ; i++ ) 
					{
						int r = UnityEngine.Random.Range( 0 , 3 );
						map[ i ] = id[ r ];
					}
				}
			}
			
			
		}  
		
	}
	
	
	public int getBattleMap( int mID )
	{
		return map[ mID ];
	}

	public void initConfig()
	{
		load( "battleMap" );
	}
	
	public void clearConfig()
	{

	}


}
